#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
        int len = -1;
        int target = 0;
        for (auto e : nums)
        {
            target += e;
        }
        target -= x;
        if (target < 0)
        {
            return -1;
        }
        for (int left = 0, right = 0, sum = 0; right < nums.size(); right++)
        {
            sum += nums[right];
            while (sum > target)
            {
                sum -= nums[left];
                left++;

            }
            if (sum == target)
            {
                len = max(len, right - left + 1);
            }


        }
        if (len == -1)
        {
            return -1;
        }
        return nums.size() - len;

    }
};